package top.waikin.aspect.service;

import org.springframework.stereotype.Service;
import top.waikin.aspect.annonation.ClearCache;
import top.waikin.aspect.annonation.EnableCache;
import top.waikin.aspect.annonation.Key;
import top.waikin.aspect.annonation.RequireCache;
import top.waikin.aspect.bean.Demo;
import top.waikin.aspect.repo.DemoRepo;

import javax.annotation.Resource;

/**
 * @author WaiKin
 * @date 2022/11/29
 */
@EnableCache(keyPrefix = "cache:demo")
@Service
public class DemoService {
  @Resource DemoRepo demoRepo;

  public Long create(Demo demo) {
    return demoRepo.create(demo);
  }

  @ClearCache
  public void delete(@Key Long id) {
    demoRepo.delete(id);
  }

  @ClearCache
  public void update(@Key Long id, Demo demo) {
    demo.setId(id);
    demoRepo.update(demo);
  }

  @RequireCache
  public Demo getById(@Key Long id) {
    return demoRepo.getById(id);
  }
}
